var app = getApp();
var api = require('../../../config/api.js');
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    path: "",
    file: "",
    hidden: true,
    file: "",
    qrcode: "",
    shareType: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this
    var path = that.data.path;
    var customerId = wx.getStorageSync("customerId");
    var shareId = wx.getStorageSync("shareId");
    var spreadId = wx.getStorageSync("spreadId");
    var type = wx.getStorageSync("type");
    var token = wx.getStorageSync("token");
    if (token == "") {
      wx.showToast({
        title: '请先登录',
      })
      return;
    }
    //如果用户为分销商或者供应商，推荐人id为自己
    if ("1" == type || "0" == type) {
      shareId = customerId;
    } else if ("2" == type) {
      //如果用户为推广人，推广人id传自己id
      spreadId = customerId;
    }
    if (options.shareType == 0) {
      wx.setNavigationBarTitle({
        title: '邀请分销商',
      })
    } else {

      wx.setNavigationBarTitle({
        title: '邀请推广者',
      })
    }

    this.setData({
      shareType: options.shareType,

      imgUrl: " https://travel.fgyu.com.cn/statics/images/invite-bg.png",
      shareType: options.shareType,
      path: "/pages/index/index-new" + "?id=1" + "&shareId=" + shareId + "&spreadId=" + customerId + "&shareType=" + options.shareType,
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {




  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (options) {
    var that = this;
    var path = that.data.path1;
    var customerId = wx.getStorageSync("customerId");
    var shareId = wx.getStorageSync("shareId");
    var spreadId = wx.getStorageSync("spreadId");
    var type = wx.getStorageSync("type");
    var shareType = that.data.shareType;
    var token = wx.getStorageSync("token");
    if (token == "") {
      wx.showToast({
        title: '请先登录',
      })
      return;
    }
    //如果用户为分销商或者供应商，推荐人id为自己
    if ("1" == type || "0" == type) {
      shareId = customerId;
    } else if ("2" == type) {
      //如果用户为推广人，推广人id传自己id
      spreadId = customerId;
    }

    return {
      title: "诚邀加盟",
      imageUrl: "http://localhost:8083/statics/images/invite-bg.png",
      path: "/pages/index/index-new" + "?id=" + that.data.goodsId + "&shareId=" + shareId + "&spreadId=" + customerId + "&shareType=" + shareType,
      success: function (res) {
        wx.showToast({
          title: "成功",
          duration: 1000
        });
        setTimeout(function () {
          wx.navigateBack({
          });
        }, 1000)

      },
      fail: function (res) {
        wx.showToast({
          title: '失败',
        })
      }
    }
  },
})